package com.cold.demo.template.config;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import javax.annotation.PostConstruct;

@Slf4j
@Getter
@Setter
@SpringBootConfiguration
@ConditionalOnProperty(prefix = "project", name = "enable")
@ConfigurationProperties(prefix = "project")
public class ProjectConfig implements InitializingBean, ApplicationListener<ContextRefreshedEvent> {

    private boolean enable;

    private String serverUrl;

    private String serverHost;

    private int serverPort;

    @PostConstruct
    private void init() {
        log.info("init ===> {}", getClass().getName());
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("afterPropertiesSet ===> {}", getClass().getName());
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.info("onApplicationEvent ===> {}", getClass().getName());
    }
}
